import { http } from "@/utils/http";

export type ChargeItemItem = {
  id: number;
  name: string;
  chargetypeName: string;
  chargetypeId: number;
  remarks: string;
  createTime?: string;
  updateTime?: string;
  tenantId?: number;
};

export type ChargeItemListParams = {
  page: number;
  limit: number;
  name: string;
};

export type ChargeItemListResult = {
  code: number;
  data: {
    total: number;
    list: ChargeItemItem[];
    pageNum: number;
    pageSize: number;
    size: number;
    startRow: number;
    endRow: number;
    pages: number;
    prePage: number;
    nextPage: number;
    isFirstPage: boolean;
    isLastPage: boolean;
    hasPreviousPage: boolean;
    hasNextPage: boolean;
    navigatePages: number;
    navigatepageNums: number[];
    navigateFirstPage: number;
    navigateLastPage: number;
  };
  message: string;
};

export type ChargeItemAddParams = {
  name: string;
  chargetypeId: number;
  remarks: string;
};

export type ChargeItemUpdateParams = {
  id: number;
  name: string;
  chargetypeId: number;
  remarks: string;
};

export type ChargeItemDeleteParams = {
  id: number;
};

// 获取收费项目列表
export const getChargeItemList = (params: ChargeItemListParams) => {
  return http.request<ChargeItemListResult>(
    "post",
    "/spChargeItem/findListByQuery",
    {
      data: params
    }
  );
};

// 新增收费项目
export const addChargeItem = (params: ChargeItemAddParams) => {
  return http.request("post", "/spChargeItem/add", { data: params });
};

// 更新收费项目
export const updateChargeItem = (params: ChargeItemUpdateParams) => {
  return http.request("put", "/spChargeItem/update", { data: params });
};

// 删除收费项目
export const deleteChargeItem = (params: ChargeItemDeleteParams) => {
  return http.request("delete", `/spChargeItem/delete?id=${params.id}`);
};
